package crafex.engine.tools;
import crafex.engine.system.Command;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
 
public class Button {
	/**the texture of the button*/
	private Bitmap bmp;
	/**the x coordinate*/
	private int x = 0;
	/**the y coordinate*/
	private int y = 0;
	/**the width of hte button*/
	private int width;
	/**the height of the button*/
	private int height;
	/**the action for the button to preform when pressed*/
	protected Command command;
 
	public Button(Bitmap bmp, int x, int y) {
		this.width = bmp.getWidth();
		this.height = bmp.getHeight();
		this.bmp = bmp;
		this.x = x - (bmp.getWidth() / 2);
		this.y = y - (bmp.getHeight() / 2);
	}
       
	public Button(Bitmap bmp, int x, int y, Command command) {
		this.width = bmp.getWidth();
		this.height = bmp.getHeight();
		this.bmp = bmp;
		this.x = x - (bmp.getWidth() / 2);
		this.y = y - (bmp.getHeight() / 2);
		setCommand(command);
	}
	
	public Button(Bitmap bmp, int x, int y, int width, int height, Command command) {
		this.width = width;
		this.height = height;
		this.bmp = bmp;
		this.x = x - (bmp.getWidth() / 2);
		this.y = y - (bmp.getHeight() / 2);
		setCommand(command);
	}
 
	/**holds default drawing methods for button*/
	public void draw(Canvas canvas) {
		
		Rect src = new Rect(0, 0, width, height);
		Rect dst = new Rect(x, y, x + width, y + height);
		canvas.drawBitmap(bmp, src, dst, null);
	}
 
	/**
	 * checks if the button is being pressed
	 * @param x coordinate of touch
	 * @param y coordinate of touch
	 * @return
	 */
	public boolean isCollition(float x2, float y2) {
		return x2 > x && x2 < x + width && y2 > y && y2 < y + height;
	}
	
	/**
	 * sets the action to be preformed
	 * @param action
	 */
	public void setCommand(Command command){
		this.command = command;
	}
       
	/**
	 * gets the action that will be preformed when pressed
	 * @return
	 */
	public Command getCommand(){
		return command;
	}
}